/**
 * 
 */
package de.akabahn.ebd.fst;

import java.util.Observer;

import de.akabahn.ebd.fst.impl.FahrSteuerungAdapterImpl;
import de.akabahn.ebd.fst.impl.FahrSteuerungAdapterMock;

/**
 * Factory class to get an implementation of the
 * <code>FahrSteuerungAdapter</code> interface.
 * 
 * @author Peter Eimann
 * @since 0.2
 * @version 1.0
 */
public final class FahrSteuerungAdapterFactory {

	/**
	 * This class shouldn't be instantiated as it contains only static methods
	 */
	private FahrSteuerungAdapterFactory() {
	}

	/**
	 * Return a productive implementation of the
	 * <code>FahrSteuerungAdapter</code> interface which will be controlled by
	 * the <code>FahrSteuerungControl</code> application and which connects to
	 * default values for the server and port.
	 * 
	 * @param connectionObservers
	 *            The observer classes that want to get notified when the
	 *            connection status to the telnet server changes
	 * @return The <code>FahrSteuerungAdapter</code> implementation
	 * @see #getUncontrolledImplementation(Observer...)
	 * @see #getTestImplementation(boolean, Observer...)
	 */
	public static FahrSteuerungAdapter getControlledImplementation(Observer... connectionObservers) {
		return new FahrSteuerungAdapterImpl(true, connectionObservers);
	}

	/**
	 * Return a productive implementation of the
	 * <code>FahrSteuerungAdapter</code> interface which will be controlled by
	 * the <code>FahrSteuerungControl</code> application.
	 * 
	 * @param fstServer
	 *            The server to connect to for the Fahrsteuerung
	 * @param fstPort
	 *            The port to connect to for the Fahrsteuerung
	 * @param fstCtrlServer
	 *            The server to connect to for the Fahrsteuerung-Control (can be
	 *            <code>null</code> if the adapter should not be controlled)
	 * @param fstCtrlPort
	 *            The port to connect to for the Fahrsteuerung-Control (can be
	 *            <code>null</code> if the adapter should not be controlled)
	 * @param connectionObservers
	 *            The observer classes that want to get notified when the
	 *            connection status to the telnet server changes
	 * @return The <code>FahrSteuerungAdapter</code> implementation
	 * @see #getUncontrolledImplementation(String, int, String, int,
	 *      Observer...)
	 * @see #getTestImplementation(boolean, Observer...)
	 */
	public static FahrSteuerungAdapter getControlledImplementation(
			String fstServer, int fstPort, String fstCtrlServer,
			int fstCtrlPort, Observer... connectionObservers) {
		return new FahrSteuerungAdapterImpl(fstServer, fstPort, fstCtrlServer,
				fstCtrlPort, true, connectionObservers);
	}

	/**
	 * Return a productive implementation of the
	 * <code>FahrSteuerungAdapter</code> interface which is not controlled by
	 * the <code>FahrSteuerungControl</code> application and which connects to
	 * default values for the server and port.
	 * 
	 * @param connectionObservers
	 *            The observer classes that want to get notified when the
	 *            connection status to the telnet server changes
	 * @return The <code>FahrSteuerungAdapter</code> implementation
	 * @see #getControlledImplementation(Observer...)
	 * @see #getTestImplementation(boolean, Observer...)
	 */
	public static FahrSteuerungAdapter getUncontrolledImplementation(Observer... connectionObservers) {
		return new FahrSteuerungAdapterImpl(false, connectionObservers);
	}

	/**
	 * Return a productive implementation of the
	 * <code>FahrSteuerungAdapter</code> interface which is not controlled by
	 * the <code>FahrSteuerungControl</code> application.
	 * 
	 * @param fstServer
	 *            The server to connect to for the Fahrsteuerung
	 * @param fstPort
	 *            The port to connect to for the Fahrsteuerung
	 * @param connectionObservers
	 *            The observer classes that want to get notified when the
	 *            connection status to the telnet server changes
	 * @return The <code>FahrSteuerungAdapter</code> implementation
	 * @see #getControlledImplementation(String, int, String, int, Observer...)
	 * @see #getTestImplementation(boolean, Observer...)
	 */
	public static FahrSteuerungAdapter getUncontrolledImplementation(
			String fstServer, int fstPort, Observer... connectionObservers) {
		return new FahrSteuerungAdapterImpl(fstServer, fstPort, null, 0, false, connectionObservers);
	}

	/**
	 * Return a test implementation of the <code>FahrSteuerungAdapter</code>
	 * interface that doesn't require a telnet connection but returns fix
	 * responses instead.
	 * 
	 * @param controlled
	 *            Flag to indicate whether the adapter should be controlled by
	 *            the <code>FahrSteuerungControl</code> application or not
	 * @param connectionObservers
	 *            The observer classes that want to get notified when the
	 *            connection status to the telnet server changes
	 * @return The <code>FahrSteuerungAdapter</code> implementation
	 * @see #getControlledImplementation(Observer...)
	 * @see #getUncontrolledImplementation(Observer...)
	 */
	public static FahrSteuerungAdapter getTestImplementation(boolean controlled, Observer... connectionObservers) {
		return new FahrSteuerungAdapterMock(controlled, connectionObservers);
	}
}
